
import axios from 'axios'

export function request(config) {
  const instance1 = axios.create({
    baseURL: 'http://127.0.0.1:9898',
    timeout: 500000
  })

  // 请求拦截 
  instance1.interceptors.request.use(config => {
    if (localStorage.getItem('token')) {
        config.headers.Authorization = localStorage.getItem('token')
      }

    return config
   
  }, err => {
    return err
  })

  // 响应拦截
  instance1.interceptors.response.use(resp => {
    // 前台根据后台的响应确定token是否正确
    console.log('**********拦截token**********');
    // console.log('错误代码' + resp.data.err);
    // if (resp.data.err === 401) {
    //   router.push({
    //     path:'/login'
    //   })
    // }
      return resp
  }, err => {
    return err
  })

  return instance1(config)
}